From 152e26469e6853273cb26143983f743db510c040 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Wed, 4 Jul 2018 22:53:22 -0500 Subject: [PATCH] Fix delete/xfree mismatch in xmltag copy Other misc minor changes tweaks identified by codacy during last commit. --- arcdist.cc | 2 +- lowranceusr4.cc | 7 +++---- mtk_logger.cc | 6 +++--- psitrex.cc | 5 ++--- tpo.cc | 32 ++++++++++++++------------------ xmltag.cc | 2 +- 6 files changed, 24 insertions(+), 30 deletions(-) diff --git a/arcdist.cc b/arcdist.cc index ac97fb8dd..9174f4b03 100644 --- a/arcdist.cc +++ b/arcdist.cc @@ -47,7 +47,7 @@ void ArcDistanceFilter::arcdist_arc_disp_wpt_cb(const Waypoint* arcpt2) #else queue* elem, * tmp; QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint * waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; #endif double dist; extra_data* ed; diff --git a/lowranceusr4.cc b/lowranceusr4.cc index efd1d5e35..7670042b9 100644 --- a/lowranceusr4.cc +++ b/lowranceusr4.cc @@ -349,7 +349,6 @@ lowranceusr4_parse_waypoints() { short int icon_num; unsigned int i, num_waypts, create_date, create_time; - int text_len; char buff[MAXUSRSTRINGSIZE + 1]; num_waypts = gbfgetint32(file_in); @@ -401,7 +400,7 @@ lowranceusr4_parse_waypoints() gbfgetint16(file_in); /* Waypoint name; input is 2 bytes per char, we convert to 1 */ - text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); + int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; wpt_tmp->shortname = buff; @@ -585,7 +584,7 @@ lowranceusr4_parse_routes() static void lowranceusr4_parse_trails() { - int num_trails, M, i, j, k, trk_num, text_len; + int num_trails, M, i, j, k, trk_num; char buff[MAXUSRSTRINGSIZE + 1]; Waypoint* wpt_tmp; @@ -649,7 +648,7 @@ lowranceusr4_parse_trails() gbfgetint16(file_in); /* Trail name; input is 2 bytes per char, we convert to 1 */ - text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); + int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; trk_head->rte_name = buff; diff --git a/mtk_logger.cc b/mtk_logger.cc index f5c53b4f7..7ac789886 100644 --- a/mtk_logger.cc +++ b/mtk_logger.cc @@ -499,7 +499,7 @@ static void mtk_rd_deinit() static int mtk_erase() { - int log_status, err; + int log_status; char* lstatus = nullptr; log_status = 0; @@ -529,8 +529,8 @@ static int mtk_erase() gb_sleep(100*1000); if ((log_status & 2)) { // auto-log were enabled before..re-enable log. - err = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2); - dbg(3, "re-enable log %s\n", err==0?"Success":"Fail"); + int err = do_cmd(CMD_LOG_ENABLE, "PMTK001,182,4,3", nullptr, 2); + dbg(3, "re-enable log %s\n", err == 0 ? "Success" : "Fail"); } return 0; } diff --git a/psitrex.cc b/psitrex.cc index 611572626..eed700e28 100644 --- a/psitrex.cc +++ b/psitrex.cc @@ -459,12 +459,11 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) Waypoint* testwpt; /* total nodes (waypoints) this route */ - unsigned int rte_datapoints = 0; if (rte->waypoint_list.next) { // this test doesn't do what I w ant i.e test if this is a valid // route - treat as a placeholder for now . - time_t uniqueValue = 0; + unsigned int rte_datapoints = 0; queue *elem, *tmp; QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { testwpt = (Waypoint*)elem; @@ -608,9 +607,9 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) if (psit_track_state == 2) { /* total nodes (waypoints) this track */ - unsigned int trk_datapoints = 0; if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ + unsigned int trk_datapoints = 0; QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { if (trk_datapoints == 0) { Waypoint* testwpt = (Waypoint*)elem; diff --git a/tpo.cc b/tpo.cc index 38a697a0c..f3896490b 100644 --- a/tpo.cc +++ b/tpo.cc @@ -259,8 +259,6 @@ static void tpo_read_2_x() { char buff[16]; short track_count, waypoint_count; - double lat_scale, lon_scale, amt; - int i, j; /* track count */ track_count = gbfgetint16(tpo_file_in); @@ -273,7 +271,7 @@ static void tpo_read_2_x() /* chunk name: "CTopoRoute" */ gbfread(&buff[0], 1, 12, tpo_file_in); - for (i=0; i lat_delta(waypoint_count); std::vector lon_delta(waypoint_count); - for (j = 0; j < waypoint_count; j++) { + for (int j = 0; j < waypoint_count; j++) { /* get this point's longitude delta from the first waypoint */ lon_delta[j] = gbfgetint16(tpo_file_in); @@ -323,10 +321,10 @@ static void tpo_read_2_x() } /* 8 bytes - longitude delta to degrees scale */ - lon_scale = gbfgetdbl(tpo_file_in); + double lon_scale = gbfgetdbl(tpo_file_in); /* 8 bytes - latitude delta to degrees scale */ - lat_scale = gbfgetdbl(tpo_file_in); + double lat_scale = gbfgetdbl(tpo_file_in); /* 4 bytes: the total length of the route in feet*/ gbfread(&buff[0], 1, 4, tpo_file_in); @@ -338,14 +336,14 @@ static void tpo_read_2_x() gbfread(&buff[0], 1, 2, tpo_file_in); /* multiply all the deltas by the scaling factors to determine the waypoint positions */ - for (j = 0; j < waypoint_count; j++) { + for (int j = 0; j < waypoint_count; j++) { Waypoint* waypoint_temp = new Waypoint; - + double amt; /* convert incoming NAD27/CONUS coordinates to WGS84 */ GPS_Math_Known_Datum_To_WGS84_M( - first_lat-lat_delta[j]*lat_scale, - first_lon+lon_delta[j]*lon_scale, + first_lat-lat_delta[j] * lat_scale, + first_lon+lon_delta[j] * lon_scale, 0.0, &waypoint_temp->latitude, &waypoint_temp->longitude, @@ -489,7 +487,7 @@ static Waypoint* tpo_convert_ll(int lat, int lon) return(waypoint_temp); } -#define TRACKNAMELENGTH 256 +#define TRACKNAMELENGTH 255 class StyleInfo { public: QString name; @@ -504,8 +502,6 @@ public: static void tpo_process_tracks() { unsigned int track_count, track_style_count; - unsigned int tmp; - const int DEBUG = 0; if (DEBUG) { @@ -544,11 +540,11 @@ static void tpo_process_tracks() styles[ii].color[xx] = (uint8_t)col; } - tmp = (unsigned char) gbfgetc(tpo_file_in); + unsigned char tmp = gbfgetc(tpo_file_in); // printf("Skipping unknown byte 0x%x after color\n",tmp); // byte for name length, then name - tmp = (unsigned char) gbfgetc(tpo_file_in); + tmp = gbfgetc(tpo_file_in); // wrong byte order?? tmp = tpo_read_int(); // 16 bit value // printf("Track %d has %d-byte (0x%x) name\n", ii, tmp, tmp); if (tmp >= TRACKNAMELENGTH) { @@ -578,12 +574,12 @@ static void tpo_process_tracks() // clumsy way to skip two undefined bytes for (unsigned xx = 0; xx < 2; xx++) { - tmp = (unsigned char) gbfgetc(tpo_file_in); - // printf("Skipping final byte 0x%x\n",tmp); + tmp = gbfgetc(tpo_file_in); + // printf("Skipping final byte 0x%x\n", tmp); } if (DEBUG) { - printf("Track style %d: color=#%02x%02x%02x, width=%d, dashed=%d, name=%s\n", + printf("Track style %u: color=#%02x%02x%02x, width=%d, dashed=%d, name=%s\n", ii, styles[ii].color[0], styles[ii].color[1], styles[ii].color[2], styles[ii].wide, styles[ii].dash, qPrintable(styles[ii].name)); } diff --git a/xmltag.cc b/xmltag.cc index a9bce478c..605b92eb6 100644 --- a/xmltag.cc +++ b/xmltag.cc @@ -122,7 +122,7 @@ fs_xml_destroy(void* fs) if (xml) { free_xml_tag(xml->tag); } - xfree(fs); + delete xml; } static void -- 2.30.2